<?php
require_once(dirname(__FILE__)."/../../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../../admin/libs/member_class.php");
require_once(dirname(__FILE__)."/../../admin/libs/product_class.php");
$mb=new member();
$mc= new libstr();
$pd=new product();
//添加用户
if($mc->Ismp($_POST["addbtn"]!="")){
	if($mb->myck($_POST["rootid"])=="true"){
		echo "have child";
		exit();
	}
	$userid=$_POST["userid"];
	$password=$_POST["password"];
	$username=$_POST["username"];
	$pic="/uploadfile/userpic/moren.jpg";//默认头像
	$sex=$_POST["sex"];
	$email=$_POST["email"];
	$phone=$_POST["phone"];
	$tel=$_POST["tel"];
	$address=$_POST["address"];
	$shengri=strtotime($_POST["shengri"]);
	$qq=$_POST["qq"];
	$web=$_POST["web"];
	$rootid=$mb->getrootid($_POST["rootid"]);
	$isshow=0;//显示默认为0
	$adduserno=0;//添加人的userno
	$data=$mb->member_add($userid,$password,$username,$pic,$sex,$email,$phone,$tel,$address,$shengri,$qq,$web,$rootid,$isshow,$adduserno);
	echo $data;
	
}
//修改用户
if($mc->Ismp($_POST["editbtn"]!="")){
	if($mb->myck($_POST["rootid"])=="true"){
		echo "have child";
		exit();
	}
    $userno=$_POST["userno"];
	$username=$_POST["username"];
	$sex=$_POST["sex"];
	$email=$_POST["email"];
	$phone=$_POST["phone"];
	$tel=$_POST["tel"];
	$address=$_POST["address"];
	$shengri=strtotime($_POST["shengri"]);
	$qq=$_POST["qq"];
	$web=$_POST["web"];
	echo $rootid=$mb->getrootid($_POST["rootid"]);
    $data=$mb->member_edit($userno,$username,$rootid,$sex,$email,$phone,$tel,$address,$shengri,$qq,$web);
	echo $data;
	
}
//判断产品类别是否有子类
if($mc->Ismp($_POST["isbtn"]!="")){
	if($pd->myck($_POST["id"])=='true'){
		
		echo "have child";
	}else{
		echo "no";
	}
}
//判断身份是否有子集
if($mc->Ismp($_POST["mbisbtn"]!="")){
	if($mb->myck($_POST["id"])=='true'){
		
		echo "have child";
	}else{
		echo "no";
	}
}
//编辑权限
if ($mc->Ismp($_POST["powerbtn"]!="")){
	if($_POST["val"]!=""){
		$db->cmd("update power_class set quanxian='".$_POST["val"]."' where ID=".$_POST["id"]."");
		echo "update is ok";
	}
}

//编辑菜单
if ($mc->Ismp($_POST["menubtn"]!="")){
	if($_POST["val"]!=""){
		$db->cmd("update power_class set caidan='".$_POST["val"]."' where ID=".$_POST["id"]."");
		echo "update is ok";
	}
}

//自定义属性
if ($mc->Ismp($_POST["dfbtn"]!="")){
$_classname=$mc->request("classname","");
$_ziduan=$mc->request("ziduanname","");
$_xuanze=$mc->request("xuanze","0");
$_classorder=$mc->request("classorder","0");
$_isshow=$mc->request("isshow","1");

//判断字段是否存在
$sx=$db->ds("select * from shuxing_type where ziduan ='".$_POST["ziduanname"]."'");
if(count($sx)>0){
	echo "ziduan is exit";
	exit();
	
}
$db->cmd("insert into shuxing_type(classname,ziduan,xuanze,classorder,isshow)values('".$_classname."','".$_ziduan."',".$_xuanze.",".$_classorder.",".$_isshow.")");//插进属性类别表

$tablename=$_ziduan."_class";
$db->cmd("CREATE TABLE IF NOT EXISTS `".$tablename."` (
  `ID` int(8) unsigned NOT NULL auto_increment,
  `classname` varchar(255) collate utf8_unicode_ci default NULL,
  `pid` int(8) NOT NULL default '0',
  `depthid` int(4) NOT NULL default '0',
  `rootid` varchar(255) collate utf8_unicode_ci NOT NULL default '0,',
  `content` varchar(1000) collate utf8_unicode_ci default NULL,
  `classorder` int(8) NOT NULL default '0',
  `isshow` int(2) NOT NULL default '0',
  `lock` int(2) NOT NULL default '0',
  `cata` int(2) NOT NULL default '0',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ");//创建新的属性表

//添加字段进产品表
$db->cmd("ALTER TABLE `product_content` ADD `".$_ziduan."` VARCHAR( 500)NOT NULL DEFAULT'0' ");

echo "add is ok";

}
//修改自定义属性
if ($mc->Ismp($_POST["editdfbtn"]!="")){
$_classname=$mc->request("classname","");
$_ziduan=$mc->request("ziduanname","");
$_xuanze=$mc->request("xuanze","0");
$_classorder=$mc->request("classorder","0");
$_isshow=$mc->request("isshow","1");


$db->cmd("update shuxing_type set classname='".$_classname."',ziduan='".$_ziduan."',xuanze=".$_xuanze.",classorder=".$_classorder.",isshow=".$_isshow. " where id=".$_POST["id"]);
echo "edit is ok";
}



?>